package com.balabala.gym_goods.mapper;

import com.balabala.gym_goods.pojo.dto.AddAppointmentDto;
import com.balabala.gym_goods.pojo.dto.CourseByNameQueryDto;
import com.balabala.gym_goods.pojo.dto.CourseDto;
import com.balabala.gym_goods.pojo.dto.FindCoachByTimeDto;
import com.balabala.gym_goods.pojo.entity.CoachSchedule;
import com.balabala.gym_goods.pojo.entity.Course;
import com.balabala.gym_goods.pojo.vo.*;
import com.balabala.result.Result;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import org.apache.ibatis.annotations.Select;

import org.apache.ibatis.annotations.Update;


import java.util.List;

/**
 * @author fsj
 * @date 2023/5/5 19:31
 */
public interface CourseMapper extends BaseMapper<Course> {


    List<CourseVo> findCourseByName(CourseByNameQueryDto courseByNameQueryDto);

    @Select("SELECT cou.`name`,cou.coach_id,cs.venues_id,cs.class_order_number,cou.num_appointment,cs.start_time,cs.end_time " +
            "FROM tb_course cou,tb_coach_schedule cs WHERE cs.course_id=cou.id")
    List<CourseQueryVo> getListAll();


    @Update(" update tb_course  set num_appointment=num_appointment+#{numPeople} where id=#{courseId}")
    Boolean addNum(Long courseId, Integer numPeople);

    @Select("SELECT c.id,c.pic,c.`name`,c.coach_id,c.sort,c.time,cs.class_order_number " +
            "FROM tb_course c INNER JOIN tb_coach_schedule cs on c.id=cs.course_id")
    List<CourseFindVo> getAll();


    @Select("SELECT c.id,c.pic,c.`name`,c.coach_id,c.sort,c.time,cs.class_order_number " +
            "FROM tb_course c INNER JOIN tb_coach_schedule cs on c.id=cs.course_id and c.id=#{id} ")
    List<CourseFindVo> findById(Long id);


    //根据当前时间查询排课
    List<BookCourseAppVo> findByNewTimeByVenues(FindCoachByTimeDto findCoachByTimeDto);



    //根据时间查询排课
    List<BookCourseAppVo> findByTimeByVenues(FindCoachByTimeDto findCoachByTimeDto);

    @Select("SELECT * from tb_course where coach_id=#{id}")
    List<Course> findByCoachId(Long id);

      @Select("SELECT * from tb_coach_schedule where venues_id=#{id}")
    List<CoachSchedule> findByVenusId(Long id);
}
